using FSM.IDal; 
using FSM.IBll; 
using FSM.Model; 
using SqlSugar; 
using System; 
using System.Collections.Generic; 
using System.Text; 
 
namespace FSM.Bll 
{ 
    public class SysParamSubBll: ISysParamSubBll 
    { 
        #region 模块 
        private readonly ISysParamSubDal dal; 
        public SysParamSubBll(ISysParamSubDal dal) 
        { 
            this.dal = dal; 
        } 
        #endregion 
 
        #region 查询 
 
        /// <summary> 
        /// 根据键值查询单个信息 
        /// </summary> 
        /// <param name="sub_no">键值</param> 
        /// <returns></returns> 
        public sys_param_sub Get(int sub_no) 
        { 
            return dal.GetById(sub_no); 
        } 
 
        /// <summary> 
        /// 分页查询批量信息 
        /// </summary> 
        /// <param name="param_no">参数编号</param> 
        /// <param name="sub_name">子参数显示值</param> 
        /// <param name="sub_value">子参数保存值</param> 
        /// <param name="page">页码</param> 
        /// <param name="page_size">每页显示的条数</param> 
        /// <returns></returns> 
        public Tuple<List<sys_param_sub>, int> ListPagin(int? param_no, string sub_name, string sub_value, int page, int page_size) 
        { 
            ISugarQueryable<sys_param_sub> queryable = dal.CreateQueryable();
            queryable = queryable.WhereIF(param_no != null, p => p.param_no == param_no);
            queryable = queryable.WhereIF(!string.IsNullOrEmpty(sub_name),p => p.sub_name == sub_name); 
            queryable = queryable.WhereIF(!string.IsNullOrEmpty(sub_value),p => p.sub_value == sub_value); 
             
            PageModel pm = new PageModel 
            { 
                PageIndex = page, 
                PageSize = page_size 
            }; 
            Tuple<List<sys_param_sub>, int> result = dal.GetPageListAndTotal(queryable, pm); 
            return result; 
        }

        /// <summary> 
        /// 分页查询批量信息 
        /// </summary> 
        /// <param name="param_no">参数编号</param> 
        /// <param name="sub_name">子参数显示值</param> 
        /// <param name="sub_value">子参数保存值</param> 
        /// <returns></returns> 
        public List<sys_param_sub> List(int? param_no, string sub_name, string sub_value)
        {
            Expressionable<sys_param_sub> queryable = Expressionable.Create<sys_param_sub>();
            queryable = queryable.AndIF(param_no != null, p => p.param_no == param_no);
            queryable = queryable.AndIF(!string.IsNullOrEmpty(sub_name), p => p.sub_name == sub_name);
            queryable = queryable.AndIF(!string.IsNullOrEmpty(sub_value), p => p.sub_value == sub_value);

            List<sys_param_sub> result = dal.GetList(queryable.ToExpression());
            return result;
        }
 
        #endregion 
 
        #region 提交 
 
        /// <summary> 
        /// 添加 
        /// </summary> 
        /// <param name="model">实体</param> 
        /// <returns></returns> 
        public bool Insert(sys_param_sub model) 
        { 
            model.create_date = DateTime.Now;
            model.sub_no = dal.GetNewID();
            return dal.Insert(model); 
        } 
 
        /// <summary> 
        /// 更新 
        /// </summary> 
        /// <param name="model">实体</param> 
        /// <returns></returns> 
        public bool Update(sys_param_sub model) 
        { 
            model.edit_date = DateTime.Now; 
            return dal.UpdateExcludeColumns(model, "creater", "create_date") == 1; 
        } 
 
        /// <summary> 
        ///  删除 
        /// </summary> 
        /// <param name="sub_no">键值</param> 
        /// <returns></returns> 
        public bool Delete(params int[] sub_no_arr) 
        { 
            return dal.Delete(sub_no_arr); 
        } 
        #endregion 
    } 
} 
